//时间拼接JS函数
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

$(function() {
	list.init();
	
});
var list = {
	init : function() {
		//禁止滚动条
		  $(document.body).css({
		    "overflow-x":"hidden",
		    "overflow-y":"hidden"
		  });

		  $(".modal-dialog").css({
			  "overflow-x":"auto",
			  "overflow-y":"auto"
		  });
		  
		list.loadDataList();
		$("#beginDate").datepicker({
			onSelect: function(dateText, inst) {
			    	  var arys = new Array();   
			    	  var arys = dateText.split('-');   
			    	  $('#endDate').datepicker('option', 'minDate', new Date(arys[0],arys[1]-1,arys[2]));
			 }
		});
			 
		$("#endDate").datepicker({
			onSelect: function(dateText, inst) {
			    var arys = new Array();   
					var arys = dateText.split('-');   
				    $('#beginDate').datepicker('option', 'maxDate', new Date(arys[0],arys[1]-1,arys[2]));
			}
		});
		
		$("#auditingBtn").click(list.auditing);
		$("#search").click(function() {
			list.loadDataList();
			
		});
		
		$("#empty").click(function() {
			$("#beginDate").val("");
			$("#endDate").val("");
			
		});
	},
	loadDataList : function() {
		$.ajax({
			url : ctx + '/auditing/reviewList',
			type : 'POST',
			data : $("#_listForm").serialize(),
			dataType : 'html',
			success : function(data) {
				$("#_dataList").html(data);
				var len = $("#_dataList #time").size();//获取span标签的个数
				var arr = [];
				for(var index = 0; index < len; index++){//创建一个数字数组
					arr[index] = index;
				}
				
				$.each(arr, function(i){//循环得到不同的id的值
					var time = $("#_dataList #time").eq(i).html().trim();
					var a = parseInt(time*1000); 
					
					if(a){
						var mydate = new Date(a);
						var datetime = mydate.getFullYear()
		                + "-"// "年"
		                + ((mydate.getMonth() + 1) > 10 ? (mydate.getMonth() + 1) : "0"
		                        + (mydate.getMonth() + 1))
		                + "-"// "月"
		                + (mydate.getDate() < 10 ? "0" + mydate.getDate() : mydate
		                        .getDate());
						$("#_dataList #time").eq(i).html(datetime);
					}
				});
				$("a[id=auditingBtn]").click(list.auditing,this);
				$("#auditingSave").click(list.auditingSave);
			}
		});
	},
	auditing:function(id){
		$('#reviewMyModal').modal({
			keyboard : true
		});
		$.ajax({
			url : ctx + '/auditing/edit',
			type : 'POST',
			data : {id:id},
			dataType : 'html',
			success : function(data) {
				 var obj = eval("("+data+")");  
				 $("#nickname").val(obj.nickname);
				 $("#username").val(obj.username);
				 $("#phone").val(obj.phone);
				 $("#identity").val(obj.identity);
				 $("#bankAccount").val(obj.bankAccount);
				 $("#bankAddress").val(obj.bankAddress);
				 $("#address").val(obj.address);
				 $("#proportion").val(obj.proportion);
				 $("#audityingId").val(obj.id);
				 $("#reviewPoint").val(obj.reviewPoint);
				 
			}
		});
		
		
	},auditingSave:function(){
		
		var audityingId = $("#audityingId").val();
		var reviewStatus = $("#statusUpdate").val();
		$.ajax({
			url : ctx + '/auditing/updateReviewStatus',
			type : 'POST',
			data : {id:audityingId,reviewStatus:reviewStatus},
			dataType : 'html',
			success : function(data) {
				list.loadDataList();
			}
		});
		
		$('#reviewMyModal').modal('hide');
		
	}
};